<?php
/**
 * RabbitCMS
 */

class News_Widgets_Newest_Widget extends Tomato_Widget 
{
	protected function _prepareShow() 
	{
		$limit      = (int) $this->_request->getParam('limit', 4);
		$categoryId = $this->_request->getParam('category_id', null);
		
		$articleModel = Rabbit_Model_Factory::getInstance()->setModule('news')->getArticleModel();
		
		/**
		 * @since 2.0.8
		 */
		//$articleDao->setLang($this->_request->getParam('lang'));
		
		$exp = array('status' => 'actived'); //change active to actived by tronghm
		if ($categoryId != null && $categoryId != '') {
			$exp['category_id'] = $categoryId;
		}
		$articles = $articleModel->find(0, $limit, $exp);
		$this->_view->assign('articles', $articles);
		
		/**
		 * @since 2.0.8
		 */
		$this->_view->assign('dateFormat', array(
			'DAY' 			=> $this->_view->translator()->widget('diff_day_format'),
			'DAY_HOUR'		=> $this->_view->translator()->widget('diff_day_hour_format'),
			'HOUR' 			=> $this->_view->translator()->widget('diff_hour_format'),
			'HOUR_MINUTE' 	=> $this->_view->translator()->widget('diff_hour_minute_format'),
			'MINUTE' 		=> $this->_view->translator()->widget('diff_minute_format'),
			'MINUTE_SECOND'	=> $this->_view->translator()->widget('diff_minute_second_format'),
			'SECOND'		=> $this->_view->translator()->widget('diff_second_format'),
		));
	}
	
	protected function _prepareConfig() 
	{
		$categoryModel = Rabbit_Model_Factory::getInstance()->setModule('category')->getCategoryModel();
		$categories = $categoryModel->getTree();
		
		$this->_view->assign('categories', $categories);
	}
}
